package com.zhangfei.controller;

import com.zhangfei.selector.PayTypeEnum;
import com.zhangfei.selector.PayHandlerSelector;
import com.zhangfei.selector.PayHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(("/payController"))
public class PayController {

    @Resource
    private PayHandlerSelector payHandlerSelector;

    @GetMapping("/pay")
    public String pay(Integer payType) {
        // 1.根据支付方式选择付款处理器
        PayHandler select = payHandlerSelector.select(PayTypeEnum.getTypeByValue(payType));
        
        //2.开始付款
        String result = select.pay("付款信息");

        System.out.println(result);
        return result;
    }



    @GetMapping("/pay2")
    public String pay2(Integer payType) {
       if(payType==1){
           //业务处理
       }else if(payType==2){
           //业务处理
       }else if(payType==3){
           //业务处理
       }else {
           //业务处理
       }

        return "success";
    }
}
